//Team: T102-17 
//Members: wrr3hw/ William Rinaldi; atb3df/ Austin Beane; cea7dz/ Katie Aichholz; jpp7mt/Jessica Platter

package cs2110.virginia.edu.ghosthunter;

import android.app.Activity;
import android.app.ListActivity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.TextView;

public class MainGame extends Activity {

	MediaPlayer gameMusic;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		setContentView(R.layout.activity_main);
		
//		 TextView coinChange = (TextView)findViewById(R.id.textval);
//		 coinChange.setText(numberOfCoins);
		
		
//		 TextView superBombChange = (TextView)findViewById(R.id.numberofbombs);
//		 superBombChange.setText(numberOfSuperBombs);
		 
//		 TextView ghostChange = (TextView)findViewById(R.id.ghost);
//		 ghostChange.setText(numberOfGhostsLeft);
		
		/* SurfaceView v = (SurfaceView) findViewById(R.id.surfaceView1);
        GifRun w = new  GifRun();
        w.LoadGiff(v, this, R.drawable.coin);*/
		
		Thread playMainMusic = new Thread() {
			public void run() {
				gameMusic = MediaPlayer.create(MainGame.this, R.raw.horror_music);
				gameMusic.setLooping(true);
			}
		};
		playMainMusic.run();
		
		Thread checkLives = new Thread() {
			
		};
		
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		gameMusic.start();
		
	}
	

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		gameMusic.pause();
	}
	
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		gameMusic.stop();
	}

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
    
    
    public void sendMessageUp(View view) {
		if (Drawer.bill.gety() > 20) {
			Drawer.bill.sety(Drawer.bill.gety() - 50);
		}
	}
	public void sendMessageDown(View view) {
		if (Drawer.bill.gety() < 850) {
			Drawer.bill.sety(Drawer.bill.gety() + 50);
			
		}
	}
	public void sendMessageLeft(View view) {
		if (Drawer.bill.getx() > 30 ) {
			Drawer.bill.setx(Drawer.bill.getx() - 50);
		}
	}
	public void sendMessageRight(View view) {
		if (Drawer.bill.getx() < 660) {
			Drawer.bill.setx(Drawer.bill.getx() + 50);
		}
	}
     
     
     public void pauseMenu (View view) {
 		onPause();
 		setContentView(R.layout.pause_menu); 		
     }
     
     public void leavePauseMenu (View view) {
    	 onResume();
     }
     
     public void quitGame (View view) {
    	 finish();
    	 onResume();
     }
   
     public void dropSuperBomb (View view) {
       	 if (Drawer.numberOfSuperBombs > 0) {
       		 Drawer.numberOfGhostsLeft = Drawer.numberOfGhostsLeft - Drawer.ghostlist.size();
       		 Drawer.ghostlist.removeAll(Drawer.ghostlist);
       		 Drawer.numberOfSuperBombs--;
       	 }
        }
        
     
     public void dropMine(View view) {
    	 //Drawer.mine1.setx(billXCoord);
    	 //Drawer.mine1.sety(billYCoord);
    	 
// 		Thread dropTheMine = new Thread() {
//			public void run() {
//	    		try { 
	    	    	 int billXCoord = Drawer.bill.getx();
	    	    	 int billYCoord = Drawer.bill.gety();
	    			Drawer.minelist.add(new Mine(billXCoord, billYCoord));
	    			
//	    		}
//	    		
//	    		catch (NullPointerException somethingIsWrong) {
//	    			
//	    		}
//	    		
//	    		finally {
//	    			
//	    		}
//	    	}
//	    };
//	    
//	    dropTheMine.run();
//	    
     }
     
     
     
 	public void pauseGame(View view){
 		onPause();
		
		Thread pauseButtonClicked = new Thread() {
			public void run() {
	    		try {
	    			Intent pauseGameIntent = new Intent("cs2110.virginia.edu.ghosthunter.PAUSEMENU");
	    			startActivity(pauseGameIntent);
	    			
	    		}
	    		
	    		catch (ActivityNotFoundException activityIsMissing) {
	    			
	    		}
	    		
	    		finally {
	    			
	    		}
	    	}
	    };
	    
	    pauseButtonClicked.run();
		
	}

    public void billDies(View view) {
    	if (Drawer.numberOfLives == 0) {
	    	Thread billDied = new Thread() {
				public void run() {
					try {
		    			Intent restartGameIntent = new Intent("cs2110.virginia.edu.ghosthunter.STARTSCREEN");
		    			startActivity(restartGameIntent);
		    			
		    		} catch (IllegalStateException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
		    		
		    		finally {
		    			finish();
		    		}
		    	}
		    };
		    billDied.start();
    		}
	    }
}
     




